<?php
	session_start();
	require_once("../../db/dbclass.php");
	require_once("../../model/userinfo.php");
	require_once("../../utils/common.php");
	$myDb=&DbController::getInstance();
	$myplug=new Plugin();
	$myimg=new UpdateUserInfo();
	$plugin_author="";
	if(isset($_SESSION['name'])){
		$plugin_author=$_SESSION['name'];
	}
	// $param="SELECT * FROM yj_user_info where user_name='".$plugin_author."'";
	// $result=$myDb->exec_query($param);
	// if($result==TRUE){
	// 	while($row=mysqli_fetch_array($result,MYSQL_ASSOC)){
	// 		$plugin_author=$row['user_id'];
	// 	}
	// }
	$plug_name=$_POST['plugin_name'];
	$plug_vision=$_POST['plugin_vision'];
	$introduce=$_POST['introduce'];
	$myplug->vision=$plug_vision;
	$myplug->plug_name=$plug_name;
	getFile("uploadImg",$plugin_author,$myimg,2);
	getFile("pluginzip",$plugin_author,$myplug,3);
	if($myplug->result==TRUE){
		$param="select * from yj_plugin where plugin_name='".$plug_name."'";
		$result=$myDb->exec_query($param);
		if($result==TRUE){
			$row=mysqli_num_rows($result);
			if($row==0){
				$param="INSERT INTO yj_plugin(plugin_name,plugin_vision,plugin,plugin_introduce,plugin_picture,author_id,issue_time) VALUES ('".$plug_name."','".$plug_vision."','".$myplug->img_url."','".$introduce."','".$myimg->img_url."','".$plugin_author."','".date('y-m-d',time())."')";
				$result=$myDb->exec_query($param);
				if($result==TRUE){
					echo "{'result':'1'}";
					return;
				}
			}
			else{
				$param="UPDATE yj_plugin SET plugin='".$myplug->img_url."',plugin_picture='".$myimg->img_url."',plugin_vision='".$plug_vision."',issue_time='".date('y-m-d',time())."',plugin_introduce='".$introduce."',author_id='".$plugin_author."' where plugin_name='".$plug_name."'";
				$result=$myDb->exec_query($param);
				if($result==TRUE){
					echo "{'result':'1'}";
					return;
				}
			}
		}
	}
	echo "{'result':'2'}";
?>